package azcat.planner.gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JList;
import java.awt.BorderLayout;
import javax.swing.AbstractListModel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JSpinner;
import javax.swing.JProgressBar;
import javax.swing.JToggleButton;
import javax.swing.JPanel;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;
import javax.swing.JCheckBox;
import javax.swing.JTextField;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.ComponentOrientation;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.awt.Dialog.ModalExclusionType;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ToolsWindow extends JFrame implements ItemListener{

	private JPanel frmHerramientas;
	private JPanel toolsListPanel;
	private JPanel buttonsPanel;
	private JCheckBox chckbxWarcoT;
	private JLabel lblHerramientas;
	private JLabel lblOrdenDeUso;
	private JCheckBox chckbxOpCortesManuales;
	private JCheckBox chckbxOpDeSierra;
	private JCheckBox chckbxOpDeSierra_2;
	private JCheckBox chckbxOpDeSierra_3;
	private JCheckBox chckbxOpDeSierra_4;
	private JCheckBox chckbxOpTermoformado;
	private JCheckBox chckbxMesaDeLiners;
	private JCheckBox chckbxPistolaDeAire;
	private JCheckBox chckbxMarcarCartonO;
	private JCheckBox chckbxSellarBolsas;
	private JCheckBox chckbxScorearGrapar;
	private JComboBox comboBox_1;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private JTextField textField_11;
	private JTextField textField_12;
	private JLabel lblHerramientas_1;
	private JLabel lblOrdenDeUso_1;
	private JCheckBox chckbxLimpiarCoroplastO;
	private JCheckBox chckbxPistolaDeHot;
	private JCheckBox chckbxMesaDeCortes;
	private JCheckBox chckbxLimpiarCelluplankO;
	private JCheckBox chckbxPonerPerfilesCon;
	private JCheckBox chckbxPonerRibets;
	private JCheckBox chckbxPonerCorbatas;
	private JCheckBox chckbxColocarPiezaEn;
	private JCheckBox chckbxNewCheckBox;
	private JCheckBox chckbxEmpaqueDeProducto;
	private JCheckBox chckbxPrensarProductoLaminado;
	private JCheckBox chckbxPegarConAplicador;
	private JCheckBox chckbxPerforarCintosNylon;
	private JTextField textField_13;
	private JTextField textField_14;
	private JTextField textField_15;
	private JTextField textField_16;
	private JTextField textField_17;
	private JTextField textField_18;
	private JTextField textField_19;
	private JTextField textField_20;
	private JTextField textField_21;
	private JTextField textField_22;
	private JTextField textField_23;
	private JTextField textField_24;
	private JButton btnAceptar;
	private JButton btnCancelar;
	private HashMap<String,JTextField> boxToText = new HashMap<String, JTextField>();
	private JPanel panel;
	private ArrayList<String> selectedTools = new ArrayList<String>();
	private MainWindow mw;

	/**
	 * Launch the application.
	 */
//	public static void main(String[] args) {
//		EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				try {
//					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//					ToolsWindow window = new ToolsWindow();
//					window.frmHerramientas.setVisible(true);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		});
//	}

	/**
	 * Create the application.
	 */
	public ToolsWindow(MainWindow mw) {
		this.mw = mw;
		setAlwaysOnTop(true);
		initialize();
		initializeMap();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		setSize(new Dimension(600, 460));
		setResizable(false);
		setTitle("Herramientas");
		setBounds(100, 100, 600, 460);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		panel = new JPanel();
		getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(new BorderLayout(0, 0));
		
		toolsListPanel = new JPanel();
		panel.add(toolsListPanel, BorderLayout.CENTER);
		toolsListPanel.setLayout(new MigLayout("", "[][79.00][70.00][][][][]", "[][][][][][][][][][][][][][]"));
		
		lblHerramientas = new JLabel("Herramientas");
		lblHerramientas.setFont(new Font("Tahoma", Font.BOLD, 13));
		toolsListPanel.add(lblHerramientas, "cell 0 0,alignx center");
		
		lblOrdenDeUso = new JLabel("Orden de uso");
		lblOrdenDeUso.setFont(new Font("Tahoma", Font.BOLD, 13));
		toolsListPanel.add(lblOrdenDeUso, "cell 1 0 2 1");
		
		lblHerramientas_1 = new JLabel("Herramientas");
		lblHerramientas_1.setFont(new Font("Tahoma", Font.BOLD, 13));
		toolsListPanel.add(lblHerramientas_1, "cell 3 0,alignx center");
		
		lblOrdenDeUso_1 = new JLabel("Orden de uso");
		lblOrdenDeUso_1.setFont(new Font("Tahoma", Font.BOLD, 13));
		toolsListPanel.add(lblOrdenDeUso_1, "cell 4 0");
		
		chckbxWarcoT = new JCheckBox("WARCO 150 T");
		chckbxWarcoT.addItemListener(this);
		toolsListPanel.add(chckbxWarcoT, "cell 0 1");
		
		textField = new JTextField();
		textField.setEditable(false);
		toolsListPanel.add(textField, "cell 1 1,alignx center");
		textField.setColumns(3);
		
		chckbxPistolaDeHot = new JCheckBox("Pistola de Hot Mealt");
		toolsListPanel.add(chckbxPistolaDeHot, "cell 3 1");
		
		textField_13 = new JTextField();
		textField_13.setEditable(false);
		toolsListPanel.add(textField_13, "cell 4 1,alignx center");
		textField_13.setColumns(3);
		
		chckbxOpCortesManuales = new JCheckBox("OP. Cortes Manuales");
		toolsListPanel.add(chckbxOpCortesManuales, "cell 0 2");
		
		textField_1 = new JTextField();
		textField_1.setEditable(false);
		toolsListPanel.add(textField_1, "cell 1 2,alignx center");
		textField_1.setColumns(3);
		
		chckbxMesaDeCortes = new JCheckBox("Mesa de Cortes Especiales");
		toolsListPanel.add(chckbxMesaDeCortes, "cell 3 2");
		
		textField_14 = new JTextField();
		textField_14.setEditable(false);
		toolsListPanel.add(textField_14, "cell 4 2,alignx center");
		textField_14.setColumns(3);
		
		chckbxOpDeSierra = new JCheckBox("OP. de Sierra Vert. / Hor.");
		toolsListPanel.add(chckbxOpDeSierra, "cell 0 3");
		
		textField_2 = new JTextField();
		textField_2.setEditable(false);
		toolsListPanel.add(textField_2, "cell 1 3,alignx center");
		textField_2.setColumns(3);
		
		chckbxLimpiarCelluplankO = new JCheckBox("Limpiar Celluplank o Crosslink");
		toolsListPanel.add(chckbxLimpiarCelluplankO, "cell 3 3");
		
		textField_15 = new JTextField();
		textField_15.setEditable(false);
		toolsListPanel.add(textField_15, "cell 4 3,alignx center");
		textField_15.setColumns(3);
		
		chckbxOpDeSierra_2 = new JCheckBox("OP. de Sierra Dayton");
		toolsListPanel.add(chckbxOpDeSierra_2, "cell 0 4");
		
		textField_3 = new JTextField();
		textField_3.setEditable(false);
		toolsListPanel.add(textField_3, "cell 1 4,alignx center");
		textField_3.setColumns(3);
		
		chckbxPonerPerfilesCon = new JCheckBox("Poner Perfiles con Esquineros");
		toolsListPanel.add(chckbxPonerPerfilesCon, "cell 3 4");
		
		textField_16 = new JTextField();
		textField_16.setEditable(false);
		toolsListPanel.add(textField_16, "cell 4 4,alignx center");
		textField_16.setColumns(3);
		
		chckbxOpDeSierra_3 = new JCheckBox("OP. de Sierra Acra");
		toolsListPanel.add(chckbxOpDeSierra_3, "cell 0 5");
		
		textField_4 = new JTextField();
		textField_4.setEditable(false);
		toolsListPanel.add(textField_4, "cell 1 5,alignx center");
		textField_4.setColumns(3);
		
		chckbxPonerRibets = new JCheckBox("Poner Ribets / Hand Holes");
		toolsListPanel.add(chckbxPonerRibets, "cell 3 5");
		
		textField_17 = new JTextField();
		textField_17.setEditable(false);
		toolsListPanel.add(textField_17, "cell 4 5,alignx center");
		textField_17.setColumns(3);
		
		chckbxOpDeSierra_4 = new JCheckBox("OP. de Sierra Circular");
		toolsListPanel.add(chckbxOpDeSierra_4, "cell 0 6");
		
		textField_5 = new JTextField();
		textField_5.setEditable(false);
		toolsListPanel.add(textField_5, "cell 1 6,alignx center");
		textField_5.setColumns(3);
		
		chckbxPonerCorbatas = new JCheckBox("Poner Corbatas / Velcro");
		toolsListPanel.add(chckbxPonerCorbatas, "cell 3 6");
		
		textField_18 = new JTextField();
		textField_18.setEditable(false);
		toolsListPanel.add(textField_18, "cell 4 6,alignx center");
		textField_18.setColumns(3);
		
		chckbxOpTermoformado = new JCheckBox("OP. Termoformado");
		toolsListPanel.add(chckbxOpTermoformado, "cell 0 7");
		
		textField_6 = new JTextField();
		textField_6.setEditable(false);
		toolsListPanel.add(textField_6, "cell 1 7,alignx center");
		textField_6.setColumns(3);
		
		chckbxColocarPiezaEn = new JCheckBox("Colocar Pieza en Contenedor");
		toolsListPanel.add(chckbxColocarPiezaEn, "cell 3 7");
		
		textField_19 = new JTextField();
		textField_19.setEditable(false);
		toolsListPanel.add(textField_19, "cell 4 7,alignx center");
		textField_19.setColumns(3);
		
		chckbxMesaDeLiners = new JCheckBox("Mesa de Liners");
		toolsListPanel.add(chckbxMesaDeLiners, "cell 0 8");
		
		textField_7 = new JTextField();
		textField_7.setEditable(false);
		toolsListPanel.add(textField_7, "cell 1 8,alignx center");
		textField_7.setColumns(3);
		
		chckbxNewCheckBox = new JCheckBox("Armar Particion");
		toolsListPanel.add(chckbxNewCheckBox, "cell 3 8");
		
		textField_20 = new JTextField();
		textField_20.setEditable(false);
		toolsListPanel.add(textField_20, "cell 4 8,alignx center");
		textField_20.setColumns(3);
		
		chckbxPistolaDeAire = new JCheckBox("Pistola de Aire Caliente");
		toolsListPanel.add(chckbxPistolaDeAire, "cell 0 9");
		
		textField_8 = new JTextField();
		textField_8.setEditable(false);
		toolsListPanel.add(textField_8, "cell 1 9,alignx center");
		textField_8.setColumns(3);
		
		chckbxEmpaqueDeProducto = new JCheckBox("Empaque de Producto");
		toolsListPanel.add(chckbxEmpaqueDeProducto, "cell 3 9");
		
		textField_21 = new JTextField();
		textField_21.setEditable(false);
		toolsListPanel.add(textField_21, "cell 4 9,alignx center");
		textField_21.setColumns(3);
		
		chckbxMarcarCartonO = new JCheckBox("Marcar Carton o Coroplast");
		toolsListPanel.add(chckbxMarcarCartonO, "cell 0 10");
		
		textField_9 = new JTextField();
		textField_9.setEditable(false);
		toolsListPanel.add(textField_9, "cell 1 10,alignx center");
		textField_9.setColumns(3);
		
		chckbxPrensarProductoLaminado = new JCheckBox("Prensar Producto Laminado");
		toolsListPanel.add(chckbxPrensarProductoLaminado, "cell 3 10");
		
		textField_22 = new JTextField();
		textField_22.setEditable(false);
		toolsListPanel.add(textField_22, "cell 4 10,alignx center");
		textField_22.setColumns(3);
		
		chckbxSellarBolsas = new JCheckBox("Sellar Bolsas / Cajas");
		toolsListPanel.add(chckbxSellarBolsas, "cell 0 11");
		
		textField_10 = new JTextField();
		textField_10.setEditable(false);
		toolsListPanel.add(textField_10, "cell 1 11,alignx center");
		textField_10.setColumns(3);
		
		chckbxPegarConAplicador = new JCheckBox("Pegar con Aplicador de .250 ml");
		toolsListPanel.add(chckbxPegarConAplicador, "cell 3 11");
		
		textField_23 = new JTextField();
		textField_23.setEditable(false);
		toolsListPanel.add(textField_23, "cell 4 11,alignx center");
		textField_23.setColumns(3);
		
		chckbxScorearGrapar = new JCheckBox("Scorear / Grapar");
		toolsListPanel.add(chckbxScorearGrapar, "cell 0 12");
		
		textField_11 = new JTextField();
		textField_11.setEditable(false);
		toolsListPanel.add(textField_11, "cell 1 12,alignx center");
		textField_11.setColumns(3);
		
		chckbxPerforarCintosNylon = new JCheckBox("Perforar Cintos Nylon");
		toolsListPanel.add(chckbxPerforarCintosNylon, "cell 3 12");
		
		textField_24 = new JTextField();
		textField_24.setEditable(false);
		toolsListPanel.add(textField_24, "cell 4 12,alignx center");
		textField_24.setColumns(3);
		
		chckbxLimpiarCoroplastO = new JCheckBox("Limpiar Coroplast o Carton");
		toolsListPanel.add(chckbxLimpiarCoroplastO, "cell 0 13");
		
		textField_12 = new JTextField();
		textField_12.setEditable(false);
		toolsListPanel.add(textField_12, "cell 1 13,alignx center");
		textField_12.setColumns(3);
		
		buttonsPanel = new JPanel();
		panel.add(buttonsPanel, BorderLayout.SOUTH);
		FlowLayout flowLayout = (FlowLayout) buttonsPanel.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		
		btnAceptar = new JButton("Aceptar");
		btnAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				for(int i=0; i<selectedTools.size(); i++){
					mw.toolsLabels.get(i).setText(selectedTools.get(i));
				}
				dispose();
			}
		});
		buttonsPanel.add(btnAceptar);
		
		btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		buttonsPanel.add(btnCancelar);
		
		chckbxOpCortesManuales.addItemListener(this);
		chckbxOpDeSierra.addItemListener(this);
		chckbxOpDeSierra_2.addItemListener(this);
		chckbxOpDeSierra_3.addItemListener(this);
		chckbxOpDeSierra_4.addItemListener(this);
		chckbxOpTermoformado.addItemListener(this);
		chckbxMesaDeLiners.addItemListener(this);
		chckbxPistolaDeAire.addItemListener(this);
		chckbxMarcarCartonO.addItemListener(this);
		chckbxSellarBolsas.addItemListener(this);
		chckbxScorearGrapar.addItemListener(this);
		chckbxMesaDeCortes.addItemListener(this);
		chckbxLimpiarCelluplankO.addItemListener(this);
		chckbxPonerPerfilesCon.addItemListener(this);
		chckbxPonerRibets.addItemListener(this);
		chckbxPonerCorbatas.addItemListener(this);
		chckbxColocarPiezaEn.addItemListener(this);
		chckbxNewCheckBox.addItemListener(this);
		chckbxEmpaqueDeProducto.addItemListener(this);
		chckbxPrensarProductoLaminado.addItemListener(this);
		chckbxPegarConAplicador.addItemListener(this);
		chckbxPerforarCintosNylon.addItemListener(this);
		chckbxPistolaDeHot.addItemListener(this);
		chckbxLimpiarCoroplastO.addItemListener(this);

	}
	private void initializeMap(){
		
		boxToText.put("WARCO 150 T", textField);
		boxToText.put("OP. Cortes Manuales", textField_1);
		boxToText.put("OP. de Sierra Vert. / Hor.", textField_2);
		boxToText.put("OP. de Sierra Dayton", textField_3);
		boxToText.put("OP. de Sierra Acra", textField_4);
		boxToText.put("OP. de Sierra Circular", textField_5);
		boxToText.put("OP. Termoformado", textField_6);
		boxToText.put("Mesa de Liners", textField_7);
		boxToText.put("Pistola de Aire Caliente", textField_8);
		boxToText.put("Marcar Carton o Coroplast", textField_9);
		boxToText.put("Sellar Bolsas / Cajas", textField_10);
		boxToText.put("Scorear / Grapar", textField_11);
		boxToText.put("Limpiar Coroplast o Carton", textField_12);
		boxToText.put("Pistola de Hot Mealt", textField_13);
		boxToText.put("Mesa de Cortes Especiales", textField_14);
		boxToText.put("Limpiar Celluplank o Crosslink", textField_15);
		boxToText.put("Poner Perfiles con Esquineros", textField_16);
		boxToText.put("Poner Ribets / Hand Holes", textField_17);
		boxToText.put("Poner Corbatas / Velcro", textField_18);
		boxToText.put("Colocar Pieza en Contenedor", textField_19);
		boxToText.put("Armar Particion", textField_20);
		boxToText.put("Empaque de Producto", textField_21);
		boxToText.put("Prensar Producto Laminado", textField_22);
		boxToText.put("Pegar con Aplicador de .250 ml", textField_23);
		boxToText.put("Perforar Cintos Nylon", textField_24);

	}
	public void itemStateChanged(ItemEvent e){
		JCheckBox source = (JCheckBox) e.getSource();
		String text = source.getText();		
		if(source.isSelected() ){
			boxToText.get(text).setEditable(true);
			selectedTools.add(text);
		}
		else{
			boxToText.get(text).setEditable(false);
			selectedTools.remove(text);
		}
	
	}

}
